import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
// 表单校验
export const rules = reactive({
  siteId: [required],
  title: [required],
  sort: [required],
  investigateMode: [required],
  joinNum: [required],
  investigateInterval: [required],
  enabled: [required]
})

const crudSchemas = reactive<CrudSchema[]>([
  {
    label: 'ID',
    field: 'id',
    isForm: false
  },
  {
    label: '站点ID',
    field: 'siteId',
    isSearch: false,
    isTable: false,
    isForm: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '标题',
    field: 'title',
    isSearch: true
  },
  {
    label: '描述',
    field: 'description',
    isSearch: false,
    isTable: false,
    form: {
      component: 'Editor',
      componentProps: {
        valueHtml: '',
        height: 200
      }
    }
  },
  {
    label: '开始日期',
    field: 'beginDate',
    formatter: dateFormatter,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    }
  },
  {
    label: '结束日期',
    field: 'endDate',
    formatter: dateFormatter,
    isSearch: false,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    }
  },
  {
    label: '模式(1:独立访客,2:独立IP,3:独立用户)',
    field: 'investigateMode',
    isSearch: false,
    isTable: false
  },
  {
    label: '参与人次',
    field: 'joinNum',
    isSearch: false,
    isTable: true,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '重复问答间隔天数(0:不可重复问答)',
    field: 'investigateInterval',
    isSearch: false,
    isTable: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '是否启用',
    field: 'enabled',
    isSearch: true,
    isTable: true,
    dictType: DICT_TYPE.CMS_STATUS_TYPE,
    dictClass: 'number'
  },
  {
    label: '创建人ID',
    field: 'userId',
    isSearch: false,
    isTable: false,
    isForm: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    isSearch: false,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    isForm: false
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
